<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        @include('common.meta')
        <meta name="csrf-token" content="{{ csrf_token() }}">
        @include('common.script')
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="L_email" class="layui-form-label">
                            <span class="x-red">*</span>后台管理账号</label>
                        <div class="layui-input-inline">
                            <input type="hidden" name="admin_id" value="{{ $user->id }}"  />
                            <input type="text" id="L_email" name="username" required="" value="{{ $user->username }}" lay-verify="username" autocomplete="off" class="layui-input"></div>
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span>将会成为您唯一的登入名</div></div>
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>账号昵称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="L_username" name="nickname" required="" value="{{ $user->nickname }}" lay-verify="nikename" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>状态</label>
                        <div class="layui-input-block">
                            <input type="radio" {{ ($user->state == 1) ? 'checked' : '' }} name="state" value="1" title="启用" lay-skin="primary" />
                            <input type="radio" {{ ($user->state == 0) ? 'checked' : '' }} name="state" value="0" title="禁用" lay-skin="primary" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>角色</label>
                        <div class="layui-input-block">
                            @foreach($roles as $v)
                                @if(in_array($v->id,$own_rols))
                                    <input type="checkbox" checked name="role_id[]" value="{{ $v->id }}" title="{{ $v->role_name }}" lay-skin="primary" />
                                @else
                                    <input type="checkbox" name="role_id[]" value="{{ $v->id }}" title="{{ $v->role_name }}" lay-skin="primary" />
                                @endif
                            @endforeach
                        </div>
                    </div>
{{--                    <div class="layui-form-item">--}}
{{--                        <label for="L_pass" class="layui-form-label">--}}
{{--                            <span class="x-red">*</span>密码</label>--}}
{{--                        <div class="layui-input-inline">--}}
{{--                            <input type="password" id="L_pass" name="pass" required="" lay-verify="pass" autocomplete="off" class="layui-input"></div>--}}
{{--                        <div class="layui-form-mid layui-word-aux">6到16个字符</div></div>--}}
{{--                    <div class="layui-form-item">--}}
{{--                        <label for="L_repass" class="layui-form-label">--}}
{{--                            <span class="x-red">*</span>确认密码</label>--}}
{{--                        <div class="layui-input-inline">--}}
{{--                            <input type="password" id="L_repass" name="repass" required="" lay-verify="repass" autocomplete="off" class="layui-input"></div>--}}
{{--                    </div>--}}
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="edit" lay-submit="">修改</button></div>
                </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //自定义验证规则
                form.verify({
                    username: function(value) {
                        if (value.length < 5) {
                            return '后台管理账号至少得5个字符啊';
                        }
                    },
                    nickname: function(value) {
                        if (value.length < 5) {
                            return '账号昵称至少得5个字符啊';
                        }
                    },
                    // pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    // repass: function(value) {
                    //     if ($('#L_pass').val() != $('#L_repass').val()) {
                    //         return '两次密码不一致';
                    //     }
                    // }
                });

                //监听提交
                form.on('submit(edit)',
                function(data) {
                    //发异步，把数据提交给php
                    $.ajax({
                        url:'/admin/admin/'+data.field.admin_id,
                        type:'PUT',
                        dataType:'json',
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        data:data.field,
                        success:function (res){
                            // 判断
                            if(res.code == 1){
                                layer.msg(res.message,{icon:1},function (){
                                    parent.location.reload(true)
                                })
                            }else {
                                layer.msg(res.message,{icon:5})
                            }
                        },
                        error:function (res){
                        }
                    });
                    return false;
                });

            });</script>
        <script>var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();</script>
    </body>

</html>